package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig_Topic {


    public static final String Exchange_Topic_1 = "Exchange_Topic_1";

    public static final String Queue_Topic_1 = "Queue_Topic_1";
    public static final String Queue_Topic_2 = "Queue_Topic_2";
    /**
     * 统配符规则：
     * 中间以“.”分隔。
     * 符号#可以匹配零个或者多个词，符号*可以匹配一个词语。
     */

    @Bean(Exchange_Topic_1)
    public Exchange exchange_Topic_1(){
        return ExchangeBuilder.topicExchange(Exchange_Topic_1).build();
    }

    @Bean(Queue_Topic_1)
    public Queue queue_Topic_1(){
        return QueueBuilder.durable(Queue_Topic_1).build();
    }

    @Bean(Queue_Topic_2)
    public Queue queue_Topic_2(){
        return QueueBuilder.durable(Queue_Topic_2).build();
    }


    /**
     *将Queue_Direct_1 绑定到交换机Exchange_direct  with
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding binding_topic_1(
            @Qualifier(Queue_Topic_1) Queue queue,
            @Qualifier(Exchange_Topic_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.email.#").noargs();
    }

    @Bean
    public Binding binding_topic_2(
            @Qualifier(Queue_Topic_2) Queue queue,
            @Qualifier(Exchange_Topic_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.sms.#").noargs();
    }
}
